package com.xstech.library.rxjavahttp;

import android.util.Log;


import com.xstech.library.app.BaseApp;
import com.xstech.library.utils.ListUtils;

import java.io.IOException;
import java.util.HashSet;

import okhttp3.Interceptor;
import okhttp3.Response;

/**
 * @author: Allen.
 * @date: 2018/7/25
 * @description:
 */

public class CookiesSaveInterceptor implements Interceptor {
    @Override
    public Response intercept(Chain chain) throws IOException {
        Response originalResponse = chain.proceed(chain.request());

        if (!ListUtils.isEmpty(originalResponse.headers("Set-Cookie"))) {
            HashSet<String> header=new HashSet<>();
            for (String cookie : originalResponse.headers("Set-Cookie")) {
                header.add(cookie.split(";")[0]);
//                break;
            }

            SharePreferencesUtils.setString(BaseApp.getApp(),"cookiess",header);
        }
        return originalResponse;
    }

}
